﻿namespace PillBox.Client.ViewModels
{
    using System.Collections.Generic;
    using System.ComponentModel.Composition;
    using PillBox.Client.Framework;
    using PillBox.Client.Model;

    [Export]
    public class PeopleViewModel : ViewModelBase
    {
        public IEnumerable<PersonChoiceViewModel> People
        {
            get;
            set;
        }

        public override void Activate()
        {
            ResultEnumerator.Begin(this.LoadPeople());
        }

        private IEnumerable<IResult> LoadPeople()
        {
            var query = new GetPeopleQuery().AsResult();

            yield return query;

            this.People = query.Response.AsPersonChoice();

            RaisePropertyChanged(() => People);
        }
    }
}